package test;

import java.util.Timer;
import java.util.TimerTask;

import obj.Path;

public class PathTestRunnable implements Runnable {

	private CarComponent comp;

	private Path path;

	public PathTestRunnable(CarComponent c, Path p) {
		comp = c;
		path = p;
	}

	@Override
	public void run() {

		Timer panelTimer = new Timer();

		panelTimer.schedule(new TimerTask() {
			int count = 0;

			@Override
			public void run() {

				addCar(path, count);

				count++;

			}
		}, 0, 1000);

	}

	public synchronized void addCar(Path p, int count) {

		CarTest c = new CarTest(p, "" + count);

		comp.add(c);
		Runnable r = new CarTestRunnable(c, comp);
		Thread t = new Thread(r);
		t.start();
	}
}
